import io.minio.MinioClient;
import io.minio.UploadObjectArgs;

import java.io.File;

public class ChunkFileToMinIOTest {
    static MinioClient minioClient = MinioClient.builder()
            .endpoint("http://localhost:9000")
            .credentials("minioadmin", "minioadmin")
            .build();

    // 分块文件上传至minIO
    public static void main(String[] args) {
        // 分块文件应该在服务器本地已经存在了，在上传到minIO
        String chunkPath = "D:\\develop\\file_chunk\\";
        File chunkFolder = new File(chunkPath);
        try {
            File[] files = chunkFolder.listFiles();
            // 将分块文件上传到minIO
            for (int i = 0;i < files.length;i++) {
                String absolutePath = files[i].getAbsolutePath();
                int lastIndex = absolutePath.lastIndexOf("\\");
                String number = absolutePath.substring(lastIndex + 1);
                UploadObjectArgs uploadObjectArgs = UploadObjectArgs.builder()
                        .bucket("test")
                        .object("chunk/" + number)
                        .filename(absolutePath)
                        .build();

                minioClient.uploadObject(uploadObjectArgs);
                System.out.println("上传分块成功 " + i);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
